Skip to content

Ignore maxWaitTime when CSOT is enabled. #1744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

vbabanin
Copy link
Member

@vbabanin vbabanin self-assigned this Jun 19, 2025
@katcharov katcharov marked this pull request as ready for review June 19, 2025 15:06
@katcharov katcharov requested a review from a team as a code owner June 19, 2025 15:06
@katcharov katcharov requested review from nhachicha, a team and stIncMale and removed request for a team and nhachicha June 19, 2025 15:06
vbabanin added 2 commits June 26, 2025 17:52
Add JavaDoc to StartTime.
Shutdown executor properly.
@vbabanin vbabanin requested a review from stIncMale June 27, 2025 01:25
@stIncMale
Copy link
Member

The last reviewed commit is 820b131.

…entSideOperationsTimeoutProseTest.java

Co-authored-by: Valentin Kovalenko <[email protected]>
@vbabanin vbabanin requested a review from stIncMale July 30, 2025 22:17
vbabanin added 3 commits July 30, 2025 15:24
# Conflicts:
#	driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java
DRIVERS-2985: Allow on-demand client metadata updates after MongoClient initialization. (#1798)
@vbabanin vbabanin requested a review from Copilot August 10, 2025 17:30
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the functionality to ignore maxWaitTime connection pool setting when Client-Side Operation Timeout (CSOT) is enabled, meaning when timeoutMS is set. When CSOT is active, the operation timeout takes precedence over the connection pool's maximum wait time.

Key changes:

  • Modified connection pool logic to use operation timeout instead of maxWaitTime when CSOT is enabled
  • Added comprehensive test coverage for the new behavior
  • Updated timeout context methods and error handling to support the new timeout precedence

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
AbstractClientSideOperationsTimeoutProseTest.java Added three new test cases to verify maxWaitTime is ignored when timeoutMS is set
ClientSideOperationTimeoutProseTest.java Updated tearDown method signature to handle InterruptedException
DefaultConnectionPoolTest.java Added test for maxWaitTime behavior and refactored Thread.sleep usage
DefaultConnectionPool.java Core logic change to use operation timeout over maxWaitTime when CSOT is enabled
TimeoutContext.java Modified startMaxWaitTimeout method to return operation timeout when CSOT is active
MongoOperationTimeoutException.java Added @nullable annotation to constructor parameter
LogMessage.java Renamed log field from WAIT_QUEUE_TIMEOUT_MS to MAX_WAIT_TIMEOUT_MS
Timeout.java Added immutability documentation and import ordering fix
StartTime.java Added immutability documentation

TimeoutTrackingConnectionGetter connectionGetter = new TimeoutTrackingConnectionGetter(provider, timeoutSettings);
cachedExecutor.submit(connectionGetter);

sleep(70); // wait for more than maxWaitTimeMS but less than timeoutMs.
Copy link
Preview

Copilot AI Aug 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a hard-coded sleep duration makes the test fragile and dependent on timing. Consider using a more deterministic approach or at least extract this value to a constant with a descriptive name.

Suggested change
sleep(70); // wait for more than maxWaitTimeMS but less than timeoutMs.
sleep(SLEEP_BEFORE_CLOSE_MS); // wait for more than maxWaitTimeMS but less than timeoutMs.

Copilot uses AI. Check for mistakes.

}

return timeoutContext.hasTimeoutMS() ? createMongoTimeoutException(errorMessage, cause) : new MongoTimeoutException(errorMessage, cause);
}

Copy link
Preview

Copilot AI Aug 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This ternary operation creates different exception types based on the timeout context. Consider extracting this logic into a separate method to improve readability and make the intention clearer.

Suggested change
return createTimeoutExceptionBasedOnContext(errorMessage, cause, timeoutContext);
}
/**
* Creates a MongoTimeoutException based on the timeout context.
*/
private MongoTimeoutException createTimeoutExceptionBasedOnContext(String errorMessage, @Nullable MongoTimeoutException cause, TimeoutContext timeoutContext) {
if (timeoutContext.hasTimeoutMS()) {
return createMongoTimeoutException(errorMessage, cause);
} else {
return new MongoTimeoutException(errorMessage, cause);
}
}

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants